#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>

using namespace std;

class Solution 
{
public:
    vector<int> twoSum(vector<int>& nums, int target) 
    {
        unordered_map<int, int> numsMap;
        for(int i = 0; i < nums.size(); i++)
        {
            auto it = numsMap.find(target - nums[i]);
            if(it != numsMap.end())
            {
                return {i, it->second};
            }
            // numsMap.insert(pair<int, int>(nums[i], i));
            numsMap[nums[i]] = i;
        }
        return{};
    }
};

int main()
{
    Solution sol;
    vector<int> nums1 = {2, 7, 11, 15};
    int target1 = 9;
    vector<int> res1 = sol.twoSum(nums1, target1);
    cout << "测试用例1: 输入数组 {2, 7, 11, 15}, 目标值 9" << endl;
    if (!res1.empty())
        cout << "结果: " << res1[0] << ", " << res1[1] << endl;
    else
        cout << "未找到结果" << endl;

    vector<int> nums2 = {3, 2, 4};
    int target2 = 6;
    vector<int> res2 = sol.twoSum(nums2, target2);
    cout << "测试用例2: 输入数组 {3, 2, 4}, 目标值 6" << endl;
    if (!res2.empty())
        cout << "结果: " << res2[0] << ", " << res2[1] << endl;
    else
        cout << "未找到结果" << endl;

    vector<int> nums3 = {3, 3};
    int target3 = 6;
    vector<int> res3 = sol.twoSum(nums3, target3);
    cout << "测试用例3: 输入数组 {3, 3}, 目标值 6" << endl;
    if (!res3.empty())
        cout << "结果: " << res3[0] << ", " << res3[1] << endl;
    else
        cout << "未找到结果" << endl;

    vector<int> nums4 = {1, 5, 1, 5};
    int target4 = 10;
    vector<int> res4 = sol.twoSum(nums4, target4);
    cout << "测试用例4: 输入数组 {1, 5, 1, 5}, 目标值 10" << endl;
    if (!res4.empty())
        cout << "结果: " << res4[0] << ", " << res4[1] << endl;
    else
        cout << "未找到结果" << endl;

    return 0;
}
